home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / glimpsehttp / cgi-bin / artsearch < prev    next >
Encoding:
Text File  |  1995-05-16  |  2.8 KB  |  111 lines

  1. #!/usr/local/bin/perl
  2.  
  3. $HTTPD_NEWSHOME="/usr1/paul/news" ;
  4. $HTTPD_HOME="/usr1/paul/httpd" ;
  5. $GLIMPSE_LOC = "/usr/paul/bin/glimpse";
  6.  
  7. # No configuration is needed below
  8. print "Content-type: text/html\n\n";
  9. $idxfile="$HTTPD_NEWSHOME/groups/articles.db";
  10. # some beautiful piece of paranoia...
  11. $idxfile =~ s/\'/\\\'/;
  12.  
  13. # Ensure that Glimpse is available on this machine
  14. if (!-x $GLIMPSE_LOC) {
  15. #
  16. # Glimpse was not found
  17. # Report a useful message
  18. #
  19.     print <<'EOM' ;
  20. <HEAD>
  21. <TITLE>Glimpse not found</TITLE>
  22. </HEAD>
  23. <BODY>
  24. <H1>Glimpse not found</H1>
  25.  
  26. This program relies on <CODE>Glimpse</CODE> search tool.
  27. If it is installed, please set the correct path in the script file.
  28. Otherwise obtain the latest version from
  29. <A HREF="file://ftp.cs.arizona.edu/glimpse">ftp.cs.arizona.edu</A>
  30. </BODY>
  31. EOM
  32.     &diag_exit;
  33. }
  34. if (!-r $idxfile) {
  35.     print "<TITLE>Cannot open articles database</TITLE>\n";
  36.     print "<H1>Cannot open articles database</H1>\n";
  37.     print "Cannot open $idxfile: $!\n";
  38. }
  39.  
  40. #    To support an ISINDEX type search, set query string if given
  41. #    an argument on the command line
  42. $prefix="case=on&query=" if ( $#ARGV >= 0 );
  43.  
  44. $query = $ENV{'QUERY_STRING'};
  45.  
  46. $query =~ s/\'//g;
  47. #    Strip the variables out from the query string,
  48. #    and assign them into variables, prefixed by 'QS_'
  49. @qvars = split( /\&/, $prefix . $query );
  50. foreach (@qvars) {
  51.     split(/=/);
  52.     $fname = $_[0];
  53.     $fvalue = $_[1];
  54.     $cmd = "\$QS_$fname = '$fvalue';" ;
  55.     # print ">>>",$cmd,"\n";
  56.     $cmd = eval $cmd if ( $fname =~ /^[a-z_A-Z]\w*$/ );
  57. }
  58. $QS_query =~ s|\+| |g;
  59. $QS_query =~ s|%(\w\w)|sprintf("%c", hex($1))|ge;
  60. $pquery = $QS_query;
  61. $QS_query =~ s|\'|\'\"\'\"\'|g;
  62.  
  63. $OPT_errors="-$QS_errors"    if $QS_errors =~ /^[0-8]$/;
  64. $OPT_errors="-B"        if $QS_errors =~ /^Best\+match$/;
  65. $OPT_case="-i"            if $QS_case =~ /^on$/;
  66. $OPT_whole="-w"            unless $QS_whole =~ /^on$/;
  67.  
  68. if ($QS_maxlines =~ /\d+/) {
  69.     $maxlines = $& + 0;
  70. } else {
  71.     $maxlines = 200;
  72. }
  73.  
  74. #    Check that a query has been made
  75. if (!$QS_query) {
  76.     print "<TITLE>Search for news articles parameter</TITLE>\n";
  77.     print "<H1>Search for news articles parameter</H1>\n";
  78.     print "Please specify e-mail address of the author, ";
  79.     print "article ID, subject line, date, or combination of those\n";
  80.     print "<ISINDEX>\n";
  81.     exit;
  82. }
  83.  
  84. print "<HEAD><TITLE>Result for query \"$pquery\"\n";
  85. print "</TITLE></HEAD><BODY>\n";
  86. print "<H1>Result for query \"$pquery\"</H1><HR>\n";
  87.  
  88. $cmd = "exec $GLIMPSE_LOC $OPT_case $OPT_whole $OPT_errors " .
  89.      "'$QS_query' $idxfile |";
  90. open(GOUT, $cmd );
  91. $artcount = 0;
  92. print "<OL>";
  93. line: while (<GOUT>) {
  94.     chop;
  95.     $artcount++;
  96.     if ($artcount > $maxlines) {
  97.         $artcount = "at least $artcount";
  98.         print "<LI>Limit of $maxlines articles exceeded";
  99.         last line;
  100.     }
  101.     s/\&/\&/;
  102.     s/\</\</;
  103.     s/\>/\>/;
  104.     split(/\t/);
  105.     print "<LI><A HREF=\"/cgi-bin/article$_[0]\">\n";
  106.         print "$_[3] <I>$_[5]</I><BR>$_[4]</A>\n";
  107. }
  108. print "</OL><HR>Total of $artcount articles.\n";
  109. print "</BODY>\n";
  110. close(GOUT);
  111.